package com.chengww.grab_rp.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.chengww.grab_rp.database.plugin.PluginDao
import com.chengww.grab_rp.database.plugin.PluginData
import com.chengww.grab_rp.database.redpocket.RedPocket
import com.chengww.grab_rp.database.redpocket.RedPocketDao

/**
 * Created by chengww on 2/20/21
 * @author chengww
 */
@Database(
    entities = [
        PluginData::class, RedPocket::class
    ], version = 1
)
abstract class AppDatabase : RoomDatabase() {
    abstract fun pluginDao(): PluginDao

    abstract fun redPocketDao(): RedPocketDao

    companion object {
        private var INSTANCE: AppDatabase? = null

        @JvmStatic
        fun getInstance(context: Context) = INSTANCE ?: Room.databaseBuilder(
            context.applicationContext, AppDatabase::class.java, "grab_rp_db"
        )
            .fallbackToDestructiveMigration()
            .build()
            .also { INSTANCE = it }

    }
}